package com.gxa.jjty.admin.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.service.EvaluateConfigService;
import com.gxa.jjty.core.common.JsonResult;
import com.gxa.jjty.core.pojo.EvaluateConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Map;

/**
 * @ClassName EvaluateConfigController
 * @Author: ws
 * @date 2021/12/8 10:07
 */
@RestController
@RequestMapping("/evaluateConfig")
@Api(tags = "评价配置后台接口")
@Validated
public class EvaluateConfigController {

    @Autowired
    private EvaluateConfigService evaluateConfigService;

//    @PostMapping("/getALl")
//    @ApiOperation("获取所有评价配置")
//    public Map getAll(){
//
//        List<EvaluateConfig> allList = evaluateConfigService.selectAll();
//
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("1");
//        jsonResult.setData(allList);
//
//        return jsonResult.getDataMap();
//    }

    @PostMapping("/getByPage")
    @ApiOperation("分页/全查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数"),
            @ApiImplicitParam(name = "size",value = "每页记录数"),
    })
    public Map getByPage(@RequestParam("page") Integer page, @RequestParam("size") Integer size)  {

        PageInfo<EvaluateConfig> listByPage = evaluateConfigService.selectByPage(page, size);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(listByPage.getList());
        jsonResult.put("total",listByPage.getTotal());

        return jsonResult.getDataMap();
    }
    @PostMapping("/getAllBy")
    @ApiOperation("分页全/条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数"),
            @ApiImplicitParam(name = "size",value = "每页记录数"),
    })
    public Map getAllBy(@RequestParam("page") Integer page,@RequestParam("size") Integer size,
                        @RequestParam(value = "name",required = false) String name,
                        @RequestParam(value = "state",required = false) String state)  {

        PageInfo<EvaluateConfig> listByPage = evaluateConfigService.selectByPage(page, size,name,state);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(listByPage.getList());
        jsonResult.put("total",listByPage.getTotal());

        return jsonResult.getDataMap();
    }

    @PostMapping("/insert")
    @ApiOperation("添加新的评价配置")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "matterName", value = "问题名称"),
//            @ApiImplicitParam(name = "resultOne", value = "问题答案一"),
//            @ApiImplicitParam(name = "resultTwo", value = "问题答案二"),
//            @ApiImplicitParam(name = "state", value = "状态(启用/禁用)"),
//    })
    public Map insert(@RequestBody EvaluateConfig evaluateConfig){

        evaluateConfig.setCreatedTime(new Timestamp(System.currentTimeMillis()));
        EvaluateConfig insert = evaluateConfigService.insert(evaluateConfig);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(insert);

        return jsonResult.getDataMap();
    }

    @PostMapping("/delete")
    @ApiOperation("删除评价配置")
    public Map delete(Long id){

        evaluateConfigService.deleteById(id);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");

        return jsonResult.getDataMap();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新评价配置")
    public Map update(@RequestBody EvaluateConfig evaluateConfig) throws IllegalAccessException {

        Integer integer = evaluateConfigService.updateById(evaluateConfig);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");

        return jsonResult.getDataMap();
    }

}
